package com.todo.event.activity.application.convert;

import com.alibaba.fastjson.JSONObject;
import com.google.api.client.util.Lists;
import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.common.enums.BusinessSceneEnum;
import com.todo.common.utils.TodoCommonUtils;
import com.todo.event.activity.application.entity.bo.*;
import com.todo.event.activity.application.entity.condition.EventActivityConditionBO;
import com.todo.event.activity.application.entity.condition.EventDecisionConditionBO;
import com.todo.event.activity.application.entity.condition.EventInfoConditionBO;
import com.todo.event.activity.common.enums.*;
import com.todo.event.activity.iface.backend.common.ActivityExecuteInfo;
import com.todo.event.activity.iface.backend.common.ActivityRule;
import com.todo.event.activity.iface.backend.request.*;
import com.todo.event.activity.iface.backend.response.*;
import com.todo.event.activity.infrastructure.entity.condition.EventActivityCondition;
import com.todo.event.activity.infrastructure.entity.condition.EventDecisionCondition;
import com.todo.event.activity.infrastructure.entity.condition.EventInfoCondition;
import com.todo.event.activity.infrastructure.entity.domain.EventDetailDO;
import com.todo.event.activity.infrastructure.entity.po.EventActivityPO;
import com.todo.event.activity.infrastructure.entity.po.EventDecisionPO;
import com.todo.event.activity.infrastructure.entity.po.EventInfoPO;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author azhebuxing
 * @date 2025/1/7 13:23
 * @description
 */
public class EventActivityConvert {
    public static EventDetailDO convertToEventDetailDO(EventDetailBO eventDetailBO) {
        if (eventDetailBO == null) {
            return null;
        }
        EventDetailDO eventDetailDO = new EventDetailDO();
        eventDetailDO.setId(eventDetailBO.getId());
        eventDetailDO.setEventCode(eventDetailBO.getEventCode());
        eventDetailDO.setBusinessLine(eventDetailBO.getBusinessLine() == null ? null : eventDetailBO.getBusinessLine().getScene());
        if (eventDetailBO.getEventInfo() != null) {
            EventDetailBO.EventInfo eventInfoBO = eventDetailBO.getEventInfo();
            EventDetailDO.EventInfo eventInfo = new EventDetailDO.EventInfo();
            eventInfo.setEventClassify(eventInfoBO.getEventClassify() == null ? null : eventInfoBO.getEventClassify().getType());
            eventInfo.setEventType(eventInfoBO.getEventType() == null ? null : eventInfoBO.getEventType().getType());
            eventInfo.setEventName(eventInfoBO.getEventName());
            eventInfo.setTopicName(eventInfoBO.getTopicName());
            eventInfo.setTag(eventInfoBO.getTag());
            eventInfo.setConsumerName(eventInfoBO.getConsumerName());
            eventInfo.setQueueType(eventInfoBO.getQueueType() == null ? null : eventInfoBO.getQueueType().getType());
            eventInfo.setBaseConf(eventInfoBO.getBaseConf());
            eventInfo.setExtraConf(eventInfoBO.getExtraConf());
            eventInfo.setRule(eventInfoBO.getRule());
            eventDetailDO.setEventInfo(eventInfo);
        }
        if (CollectionUtils.isNotEmpty(eventDetailBO.getEventFieldList())) {
            List<EventDetailDO.EventField> result = new ArrayList<>();
            for (EventDetailBO.EventField eventFieldBO : eventDetailBO.getEventFieldList()) {
                EventDetailDO.EventField eventField = new EventDetailDO.EventField();
                eventField.setDataSource(eventFieldBO.getDataSource() == null ? null : eventFieldBO.getDataSource().getType());
                eventField.setTransfer(eventFieldBO.getTransfer());
                eventField.setFieldName(eventFieldBO.getFieldName());
                eventField.setFieldType(eventFieldBO.getFieldType() == null ? null : eventFieldBO.getFieldType().getType());
                eventField.setFieldLength(eventFieldBO.getFieldLength());
                eventField.setFieldDesc(eventFieldBO.getFieldDesc());
                eventField.setUniqueField(eventFieldBO.getUniqueField() ? 0 : 1);
                eventField.setOutput(eventFieldBO.getOutput() ? 0 : 1);
                eventField.setSelectType(eventFieldBO.getSelectType() == null ? null : eventFieldBO.getSelectType().getType());
                eventField.setSelectOperate(JSONObject.toJSONString(eventFieldBO.getSelectOperate()));
                eventField.setEnumsValue(JSONObject.toJSONString(eventFieldBO.getEnumsValue()));
                result.add(eventField);
            }
            eventDetailDO.setEventFieldList(result);
        }
        eventDetailDO.setStatus(eventDetailBO.getStatus() == null ? null : eventDetailBO.getStatus().getType());
        eventDetailDO.setCreateUser(eventDetailBO.getCreateUser());
        eventDetailDO.setLastUpdateUser(eventDetailBO.getLastUpdateUser());
        eventDetailDO.setIsDelete(0);
        eventDetailDO.setCreateTime(new Date());
        eventDetailDO.setUpdateTime(new Date());
        return eventDetailDO;
    }


    public static EventDetailBO convertToEventDetailBO(InsertEventDetailReq req) {
        if (req == null) {
            return null;
        }
        EventDetailBO eventDetailBO = new EventDetailBO();
        eventDetailBO.setId(TodoCommonUtils.buildLongGuid());
        eventDetailBO.setEventCode(req.getEventCode());
        eventDetailBO.setBusinessLine(BusinessSceneEnum.getBusinessSceneEnumByScene(req.getBusinessLine()));
        if (req.getEventInfo() != null) {
            InsertEventDetailReq.EventInfo eventInfo = req.getEventInfo();
            EventDetailBO.EventInfo eventInfoBO = new EventDetailBO.EventInfo();
            eventInfoBO.setEventClassify(EventClassifyEnum.getByType(eventInfo.getEventClassify()));
            eventInfoBO.setEventType(EventTypeEnum.getByType(eventInfo.getEventType()));
            eventInfoBO.setEventName(eventInfo.getEventName());
            eventInfoBO.setTopicName(eventInfo.getTopicName());
            eventInfoBO.setTag(eventInfo.getTag());
            eventInfoBO.setConsumerName(eventInfo.getConsumerName());
            eventInfoBO.setQueueType(EventActivityQueueType.getByType(eventInfo.getQueueType()));
            eventInfoBO.setRule(eventInfo.getRule());
            eventDetailBO.setEventInfo(eventInfoBO);
        }
        if (CollectionUtils.isNotEmpty(req.getEventFieldList())) {
            List<EventDetailBO.EventField> result = new ArrayList<>();
            for (InsertEventDetailReq.EventField eventField : req.getEventFieldList()) {
                EventDetailBO.EventField eventFieldBO = new EventDetailBO.EventField();
                eventFieldBO.setDataSource(EventFieldDataSourceEnum.getByType(eventField.getDataSource()));
                eventFieldBO.setTransfer(eventField.getTransfer());
                eventFieldBO.setFieldName(eventField.getFieldName());
                eventFieldBO.setFieldType(EventFieldTypeEnum.getByType(eventField.getFieldType()));
                eventFieldBO.setFieldLength(eventField.getFieldLength());
                eventFieldBO.setFieldDesc(eventField.getFieldDesc());
                eventFieldBO.setUniqueField(eventField.getUniqueField());
                eventFieldBO.setOutput(eventField.getOutput());
                eventFieldBO.setSelectType(EventFieldSelectTypeEnum.getByType(eventField.getSelectType()));
                if (CollectionUtils.isNotEmpty(eventField.getSelectOperate())) {
                    List<SelectOperateEnum> selectOperateEnumList = new ArrayList<>();
                    for (Integer selectOperateEnum : eventField.getSelectOperate()) {
                        selectOperateEnumList.add(SelectOperateEnum.getByType(selectOperateEnum));
                    }
                    eventFieldBO.setSelectOperate(selectOperateEnumList);
                }
                if (CollectionUtils.isNotEmpty(eventField.getEnumsValue())) {
                    List<EventDetailBO.EnumValue> enumValueList = new ArrayList<>();
                    for (InsertEventDetailReq.EnumValue enumValue : eventField.getEnumsValue()) {
                        EventDetailBO.EnumValue value = new EventDetailBO.EnumValue();
                        value.setKey(enumValue.getKey());
                        value.setDesc(enumValue.getDesc());
                        enumValueList.add(value);
                    }
                    eventFieldBO.setEnumsValue(enumValueList);
                }

                result.add(eventFieldBO);
            }
            eventDetailBO.setEventFieldList(result);
        }
        eventDetailBO.setStatus(EventDetailStatusEnum.DRAFT);
        eventDetailBO.setCreateUser(req.get_staff().getUsername());
        eventDetailBO.setLastUpdateUser(req.get_staff().getUsername());
        return eventDetailBO;
    }

    public static EventDetailBO convertToEventDetailBO(UpdateEventDetailReq req) {
        if (req == null) {
            return null;
        }
        EventDetailBO eventDetailBO = new EventDetailBO();
        eventDetailBO.setId(req.getId());
        eventDetailBO.setEventCode(req.getEventCode());
        eventDetailBO.setBusinessLine(BusinessSceneEnum.getBusinessSceneEnumByScene(req.getBusinessLine()));
        if (req.getEventInfo() != null) {
            UpdateEventDetailReq.EventInfo eventInfo = req.getEventInfo();
            EventDetailBO.EventInfo eventInfoBO = new EventDetailBO.EventInfo();
            eventInfoBO.setEventClassify(EventClassifyEnum.getByType(eventInfo.getEventClassify()));
            eventInfoBO.setEventType(EventTypeEnum.getByType(eventInfo.getEventType()));
            eventInfoBO.setEventName(eventInfo.getEventName());
            eventInfoBO.setTopicName(eventInfo.getTopicName());
            eventInfoBO.setTag(eventInfo.getTag());
            eventInfoBO.setConsumerName(eventInfo.getConsumerName());
            eventInfoBO.setQueueType(EventActivityQueueType.getByType(eventInfo.getQueueType()));
            eventInfoBO.setRule(eventInfo.getRule());
            eventDetailBO.setEventInfo(eventInfoBO);
        }
        if (CollectionUtils.isNotEmpty(req.getEventFieldList())) {
            List<EventDetailBO.EventField> result = new ArrayList<>();
            for (UpdateEventDetailReq.EventField eventField : req.getEventFieldList()) {
                EventDetailBO.EventField eventFieldBO = new EventDetailBO.EventField();
                eventFieldBO.setDataSource(EventFieldDataSourceEnum.getByType(eventField.getDataSource()));
                eventFieldBO.setTransfer(eventField.getTransfer());
                eventFieldBO.setFieldName(eventField.getFieldName());
                eventFieldBO.setFieldType(EventFieldTypeEnum.getByType(eventField.getFieldType()));
                eventFieldBO.setFieldLength(eventField.getFieldLength());
                eventFieldBO.setFieldDesc(eventField.getFieldDesc());
                eventFieldBO.setUniqueField(eventField.getUniqueField());
                eventFieldBO.setOutput(eventField.getOutput());
                eventFieldBO.setSelectType(EventFieldSelectTypeEnum.getByType(eventField.getSelectType()));
                if (CollectionUtils.isNotEmpty(eventField.getSelectOperate())) {
                    List<SelectOperateEnum> selectOperateEnumList = new ArrayList<>();
                    for (Integer selectOperateEnum : eventField.getSelectOperate()) {
                        selectOperateEnumList.add(SelectOperateEnum.getByType(selectOperateEnum));
                    }
                    eventFieldBO.setSelectOperate(selectOperateEnumList);
                }
                if (CollectionUtils.isNotEmpty(eventField.getEnumsValue())) {
                    List<EventDetailBO.EnumValue> enumValueList = new ArrayList<>();
                    for (UpdateEventDetailReq.EnumValue enumValue : eventField.getEnumsValue()) {
                        EventDetailBO.EnumValue value = new EventDetailBO.EnumValue();
                        value.setKey(enumValue.getKey());
                        value.setDesc(enumValue.getDesc());
                        enumValueList.add(value);
                    }
                    eventFieldBO.setEnumsValue(enumValueList);
                }

                result.add(eventFieldBO);
            }
            eventDetailBO.setEventFieldList(result);
        }
        eventDetailBO.setStatus(EventDetailStatusEnum.DRAFT);
        eventDetailBO.setLastUpdateUser(req.get_staff().getUsername());
        return eventDetailBO;
    }

    public static EventDetailBO convertToEventDetailBO(EventDetailDO eventDetailDO) {
        if (eventDetailDO == null) {
            return null;
        }
        EventDetailBO eventDetailBO = new EventDetailBO();
        eventDetailBO.setId(eventDetailDO.getId());
        eventDetailBO.setEventCode(eventDetailDO.getEventCode());
        eventDetailBO.setBusinessLine(BusinessSceneEnum.getBusinessSceneEnumByScene(eventDetailDO.getBusinessLine()));
        if (eventDetailDO.getEventInfo() != null) {
            EventDetailDO.EventInfo eventInfo = eventDetailDO.getEventInfo();
            EventDetailBO.EventInfo eventInfoBO = new EventDetailBO.EventInfo();
            eventInfoBO.setEventClassify(EventClassifyEnum.getByType(eventInfo.getEventClassify()));
            eventInfoBO.setEventType(EventTypeEnum.getByType(eventInfo.getEventType()));
            eventInfoBO.setEventName(eventInfo.getEventName());
            eventInfoBO.setTopicName(eventInfo.getTopicName());
            eventInfoBO.setTag(eventInfo.getTag());
            eventInfoBO.setConsumerName(eventInfo.getConsumerName());
            eventInfoBO.setQueueType(EventActivityQueueType.getByType(eventInfo.getQueueType()));
            eventInfoBO.setBaseConf(eventInfo.getBaseConf());
            eventInfoBO.setExtraConf(eventInfo.getExtraConf());
            eventInfoBO.setRule(eventInfo.getRule());
            eventDetailBO.setEventInfo(eventInfoBO);
        }
        if (CollectionUtils.isNotEmpty(eventDetailDO.getEventFieldList())) {
            List<EventDetailBO.EventField> result = new ArrayList<>();
            for (EventDetailDO.EventField eventField : eventDetailDO.getEventFieldList()) {
                EventDetailBO.EventField eventFieldBO = new EventDetailBO.EventField();
                eventFieldBO.setDataSource(EventFieldDataSourceEnum.getByType(eventField.getDataSource()));
                eventFieldBO.setTransfer(eventField.getTransfer());
                eventFieldBO.setFieldName(eventField.getFieldName());
                eventFieldBO.setFieldType(EventFieldTypeEnum.getByType(eventField.getFieldType()));
                eventFieldBO.setFieldLength(eventField.getFieldLength());
                eventFieldBO.setFieldDesc(eventField.getFieldDesc());
                eventFieldBO.setUniqueField(eventField.getUniqueField() == 0);
                eventFieldBO.setOutput(eventField.getOutput() == 0);
                eventFieldBO.setSelectType(EventFieldSelectTypeEnum.getByType(eventField.getSelectType()));
                eventFieldBO.setSelectOperate(JSONObject.parseArray(eventField.getSelectOperate(), SelectOperateEnum.class));
                eventFieldBO.setEnumsValue(JSONObject.parseArray(eventField.getEnumsValue(), EventDetailBO.EnumValue.class));
                result.add(eventFieldBO);
            }
            eventDetailBO.setEventFieldList(result);
        }

        eventDetailBO.setStatus(EventDetailStatusEnum.getByType(eventDetailDO.getStatus()));
        eventDetailBO.setCreateUser(eventDetailDO.getCreateUser());
        eventDetailBO.setLastUpdateUser(eventDetailDO.getLastUpdateUser());
        return eventDetailBO;
    }

    public static EventInfoCondition convertToEventInfoCondition(EventInfoConditionBO eventInfoConditionBO) {
        if (eventInfoConditionBO == null) {
            return null;
        }
        EventInfoCondition eventInfoCondition = new EventInfoCondition();
        eventInfoCondition.setPageIndex(eventInfoConditionBO.getPageIndex());
        eventInfoCondition.setPageSize(eventInfoConditionBO.getPageSize());
        eventInfoCondition.setEventCode(eventInfoConditionBO.getEventCode());
        eventInfoCondition.setBusinessLine(eventInfoConditionBO.getBusinessLine());
        eventInfoCondition.setCurrentIndex(eventInfoConditionBO.getCurrentIndex());
        eventInfoCondition.setEventClassify(eventInfoConditionBO.getEventClassify());
        eventInfoCondition.setEventType(eventInfoConditionBO.getEventType());
        eventInfoCondition.setEventName(eventInfoConditionBO.getEventName());
        eventInfoCondition.setTopicName(eventInfoConditionBO.getTopicName());
        eventInfoCondition.setQueueType(eventInfoConditionBO.getQueueType());
        eventInfoCondition.setStatus(eventInfoConditionBO.getStatus());
        return eventInfoCondition;
    }

    public static EventInfoBO convertToEventInfoBO(EventInfoPO eventInfoPO) {
        if (eventInfoPO == null) {
            return null;
        }
        EventInfoBO eventInfoBO = new EventInfoBO();
        eventInfoBO.setEventClassify(EventClassifyEnum.getByType(eventInfoPO.getEventClassify()));
        eventInfoBO.setEventType(EventTypeEnum.getByType(eventInfoPO.getEventType()));
        eventInfoBO.setEventCode(eventInfoPO.getEventCode());
        eventInfoBO.setBusinessLine(BusinessSceneEnum.getBusinessSceneEnumByScene(eventInfoPO.getBusinessLine()));
        eventInfoBO.setEventName(eventInfoPO.getEventName());
        eventInfoBO.setTopicName(eventInfoPO.getTopicName());
        eventInfoBO.setTag(eventInfoPO.getTag());
        eventInfoBO.setConsumerName(eventInfoPO.getConsumerName());
        eventInfoBO.setQueueType(EventActivityQueueType.getByType(eventInfoPO.getQueueType()));
        eventInfoBO.setBaseConf(eventInfoPO.getBaseConf());
        eventInfoBO.setExtraConf(eventInfoPO.getExtraConf());
        eventInfoBO.setRule(eventInfoPO.getRule());
        eventInfoBO.setStatus(EventDetailStatusEnum.getByType(eventInfoPO.getStatus()));
        eventInfoBO.setCreateUser(eventInfoPO.getCreateUser());
        eventInfoBO.setLastUpdateUser(eventInfoPO.getLastUpdateUser());
        eventInfoBO.setId(eventInfoPO.getId());
        return eventInfoBO;
    }

    public static EventDecisionPO converttoEventDecisionPO(EventDecisionBO eventDecisionBO) {
        if (eventDecisionBO == null) {
            return null;
        }
        EventDecisionPO eventDecisionPO = new EventDecisionPO();
        eventDecisionPO.setId(eventDecisionBO.getId());
        eventDecisionPO.setName(eventDecisionBO.getName());
        eventDecisionPO.setDesc(eventDecisionBO.getDesc());
        eventDecisionPO.setDecisionType(eventDecisionBO.getDecisionType() == null ? null : eventDecisionBO.getDecisionType().getType());
        eventDecisionPO.setFirstEvent(eventDecisionBO.getFirstEvent());
        eventDecisionPO.setFirstEventRule(JSONObject.toJSONString(eventDecisionBO.getFirstEventRule()));
        eventDecisionPO.setIntervalTime(eventDecisionBO.getIntervalTime());
        eventDecisionPO.setSecondEvent(eventDecisionBO.getSecondEvent());
        eventDecisionPO.setSecondEventRule(eventDecisionBO.getSecondEventRule() == null ? null : JSONObject.toJSONString(eventDecisionBO.getSecondEventRule()));
        eventDecisionPO.setUseUnique(eventDecisionBO.getUseUnique() == null ? null : eventDecisionBO.getUseUnique() ? 1 : 0);
        eventDecisionPO.setStatus(eventDecisionBO.getStatus() == null ? null : eventDecisionBO.getStatus().getType());
        eventDecisionPO.setCreateUser(eventDecisionBO.getCreateUser());
        eventDecisionPO.setLastUpdateUser(eventDecisionBO.getLastUpdateUser());
        eventDecisionPO.setIsDelete(0);
        eventDecisionPO.setCreateTime(new Date());
        eventDecisionPO.setUpdateTime(new Date());
        return eventDecisionPO;
    }

    public static EventDecisionBO convertToEventDecisionBO(UpdateEventDecisionReq req) {
        if (req == null) {
            return null;
        }
        EventDecisionBO eventDecisionBO = new EventDecisionBO();
        eventDecisionBO.setId(req.getId());
        eventDecisionBO.setName(req.getName());
        eventDecisionBO.setDesc(req.getDesc());
        eventDecisionBO.setDecisionType(DecisionTypeEnum.getByType(req.getDecisionType()));
        eventDecisionBO.setFirstEvent(req.getFirstEvent());
        if (CollectionUtils.isNotEmpty(req.getFirstEventRule())) {
            List<DecisionEventRuleBO.FieldRule> fieldRuleList = new ArrayList<>();
            for (UpdateEventDecisionReq.FieldRule fieldRule : req.getFirstEventRule()) {
                DecisionEventRuleBO.FieldRule fieldRuleBO = new DecisionEventRuleBO.FieldRule();
                fieldRuleBO.setFieldName(fieldRule.getFieldName());
                fieldRuleBO.setOperateEnum(SelectOperateEnum.getByType(fieldRule.getOperateEnum()));
                fieldRuleBO.setOperateValue(fieldRule.getOperateValue());
                fieldRuleBO.setTypeEnum(EventFieldTypeEnum.getByType(fieldRule.getTypeEnum()));
                fieldRuleList.add(fieldRuleBO);
            }
            DecisionEventRuleBO decisionEventRuleBO = new DecisionEventRuleBO();
            decisionEventRuleBO.setFieldRuleList(fieldRuleList);
            eventDecisionBO.setFirstEventRule(decisionEventRuleBO);
        }
        if (DecisionTypeEnum.getByType(req.getDecisionType()).equals(DecisionTypeEnum.MULTIPLE)) {
            eventDecisionBO.setSecondEvent(req.getSecondEvent());
            eventDecisionBO.setIntervalTime(req.getIntervalTime());
            eventDecisionBO.setUseUnique(req.getUseUnique());
            if (CollectionUtils.isNotEmpty(req.getSecondEventRule())) {
                List<DecisionEventRuleBO.FieldRule> fieldRuleList = new ArrayList<>();
                for (UpdateEventDecisionReq.FieldRule fieldRule : req.getSecondEventRule()) {
                    DecisionEventRuleBO.FieldRule fieldRuleBO = new DecisionEventRuleBO.FieldRule();
                    fieldRuleBO.setFieldName(fieldRule.getFieldName());
                    fieldRuleBO.setOperateEnum(SelectOperateEnum.getByType(fieldRule.getOperateEnum()));
                    fieldRuleBO.setOperateValue(fieldRule.getOperateValue());
                    fieldRuleBO.setTypeEnum(EventFieldTypeEnum.getByType(fieldRule.getTypeEnum()));
                    fieldRuleList.add(fieldRuleBO);
                }
                DecisionEventRuleBO decisionEventRuleBO = new DecisionEventRuleBO();
                decisionEventRuleBO.setFieldRuleList(fieldRuleList);
                eventDecisionBO.setSecondEventRule(decisionEventRuleBO);
            }
        }
        eventDecisionBO.setStatus(EventDecisionStatusEnum.DRAFT);
        eventDecisionBO.setLastUpdateUser(req.get_staff().getUsername());
        return eventDecisionBO;
    }

    public static EventDecisionBO convertToEventDecisionBO(InsertEventDecisionReq req) {
        if (req == null) {
            return null;
        }
        EventDecisionBO eventDecisionBO = new EventDecisionBO();
        eventDecisionBO.setId(TodoCommonUtils.buildLongGuid());
        eventDecisionBO.setName(req.getName());
        eventDecisionBO.setDesc(req.getDesc());
        eventDecisionBO.setDecisionType(DecisionTypeEnum.getByType(req.getDecisionType()));
        eventDecisionBO.setFirstEvent(req.getFirstEvent());
        if (CollectionUtils.isNotEmpty(req.getFirstEventRule())) {
            List<DecisionEventRuleBO.FieldRule> fieldRuleList = new ArrayList<>();
            for (InsertEventDecisionReq.FieldRule fieldRule : req.getFirstEventRule()) {
                DecisionEventRuleBO.FieldRule fieldRuleBO = new DecisionEventRuleBO.FieldRule();
                fieldRuleBO.setFieldName(fieldRule.getFieldName());
                fieldRuleBO.setOperateEnum(SelectOperateEnum.getByType(fieldRule.getOperateEnum()));
                fieldRuleBO.setOperateValue(fieldRule.getOperateValue());
                fieldRuleBO.setTypeEnum(EventFieldTypeEnum.getByType(fieldRule.getTypeEnum()));
                fieldRuleList.add(fieldRuleBO);
            }
            DecisionEventRuleBO decisionEventRuleBO = new DecisionEventRuleBO();
            decisionEventRuleBO.setFieldRuleList(fieldRuleList);
            eventDecisionBO.setFirstEventRule(decisionEventRuleBO);
        }
        if (DecisionTypeEnum.getByType(req.getDecisionType()).equals(DecisionTypeEnum.MULTIPLE)) {
            eventDecisionBO.setSecondEvent(req.getSecondEvent());
            eventDecisionBO.setIntervalTime(req.getIntervalTime());
            eventDecisionBO.setUseUnique(req.getUseUnique());
            if (CollectionUtils.isNotEmpty(req.getSecondEventRule())) {
                List<DecisionEventRuleBO.FieldRule> fieldRuleList = new ArrayList<>();
                for (InsertEventDecisionReq.FieldRule fieldRule : req.getSecondEventRule()) {
                    DecisionEventRuleBO.FieldRule fieldRuleBO = new DecisionEventRuleBO.FieldRule();
                    fieldRuleBO.setFieldName(fieldRule.getFieldName());
                    fieldRuleBO.setOperateEnum(SelectOperateEnum.getByType(fieldRule.getOperateEnum()));
                    fieldRuleBO.setOperateValue(fieldRule.getOperateValue());
                    fieldRuleBO.setTypeEnum(EventFieldTypeEnum.getByType(fieldRule.getTypeEnum()));
                    fieldRuleList.add(fieldRuleBO);
                }
                DecisionEventRuleBO decisionEventRuleBO = new DecisionEventRuleBO();
                decisionEventRuleBO.setFieldRuleList(fieldRuleList);
                eventDecisionBO.setSecondEventRule(decisionEventRuleBO);
            }
        }
        eventDecisionBO.setStatus(EventDecisionStatusEnum.DRAFT);
        eventDecisionBO.setCreateUser(req.get_staff().getUsername());
        eventDecisionBO.setLastUpdateUser(req.get_staff().getUsername());
        return eventDecisionBO;
    }

    public static EventDecisionBO convertToEventDecisionBO(EventDecisionPO eventDecisionPO) {
        if (eventDecisionPO == null) {
            return null;
        }
        EventDecisionBO eventDecisionBO = new EventDecisionBO();
        eventDecisionBO.setId(eventDecisionPO.getId());
        eventDecisionBO.setName(eventDecisionPO.getName());
        eventDecisionBO.setDesc(eventDecisionPO.getDesc());
        eventDecisionBO.setDecisionType(DecisionTypeEnum.getByType(eventDecisionPO.getDecisionType()));
        eventDecisionBO.setFirstEvent(eventDecisionPO.getFirstEvent());
        eventDecisionBO.setFirstEventRule(eventDecisionPO.getFirstEventRule() == null ? null : JSONObject.parseObject(eventDecisionPO.getFirstEventRule(), DecisionEventRuleBO.class));
        eventDecisionBO.setIntervalTime(eventDecisionPO.getIntervalTime());
        eventDecisionBO.setSecondEvent(eventDecisionPO.getSecondEvent());
        eventDecisionBO.setSecondEventRule(eventDecisionPO.getSecondEventRule() == null ? null : JSONObject.parseObject(eventDecisionPO.getSecondEventRule(), DecisionEventRuleBO.class));
        eventDecisionBO.setUseUnique(eventDecisionPO.getUseUnique() == null ? null : eventDecisionPO.getUseUnique() == 1);
        eventDecisionBO.setStatus(EventDecisionStatusEnum.getByType(eventDecisionPO.getStatus()));
        eventDecisionBO.setCreateUser(eventDecisionPO.getCreateUser());
        eventDecisionBO.setLastUpdateUser(eventDecisionPO.getLastUpdateUser());
        return eventDecisionBO;
    }

    public static EventDecisionCondition convertToEventDecisionCondition(EventDecisionConditionBO eventDecisionConditionBO) {
        if (eventDecisionConditionBO == null) {
            return null;
        }
        EventDecisionCondition eventDecisionCondition = new EventDecisionCondition();
        eventDecisionCondition.setPageIndex(eventDecisionConditionBO.getPageIndex());
        eventDecisionCondition.setPageSize(eventDecisionConditionBO.getPageSize());
        eventDecisionCondition.setCurrentIndex(eventDecisionConditionBO.getCurrentIndex());
        eventDecisionCondition.setName(eventDecisionConditionBO.getName());
        eventDecisionCondition.setDecisionType(eventDecisionConditionBO.getDecisionType());
        eventDecisionCondition.setStatus(eventDecisionConditionBO.getStatus());
        eventDecisionCondition.setCreateUser(eventDecisionConditionBO.getCreateUser());
        return eventDecisionCondition;
    }

    public static EventActivityPO convertToEventActivityPO(EventActivityBO eventActivityBO) {
        if (eventActivityBO == null) {
            return null;
        }
        EventActivityPO eventActivityPO = new EventActivityPO();
        eventActivityPO.setId(eventActivityBO.getId());
        eventActivityPO.setName(eventActivityBO.getName());
        eventActivityPO.setDesc(eventActivityBO.getDesc());
        eventActivityPO.setBusinessLine(eventActivityBO.getBusinessLine() == null ? null : eventActivityBO.getBusinessLine().getScene());
        eventActivityPO.setDecisionId(eventActivityBO.getDecisionId());
        eventActivityPO.setStartTime(eventActivityBO.getStartTime());
        eventActivityPO.setEndTime(eventActivityBO.getEndTime());
        eventActivityPO.setStatus(eventActivityBO.getStatus() == null ? null : eventActivityBO.getStatus().getType());
        eventActivityPO.setCreateUser(eventActivityBO.getCreateUser());
        eventActivityPO.setExecuteInfo(JSONObject.toJSONString(eventActivityBO.getExecuteInfoBOList()));
        eventActivityPO.setExecuteRule(JSONObject.toJSONString(eventActivityBO.getExecuteRule()));
        eventActivityPO.setIsDelete(0);
        eventActivityPO.setUpdateTime(new Date());
        eventActivityPO.setCreateTime(new Date());
        eventActivityPO.setLastUpdateUser(eventActivityBO.getLastUpdateUser());
        return eventActivityPO;
    }


    public static EventActivityBO convertToEventActivityBO(UpdateEventActivityReq req) {
        if (req == null) {
            return null;
        }
        EventActivityBO eventActivityBO = new EventActivityBO();
        eventActivityBO.setId(req.getId());
        eventActivityBO.setName(req.getName());
        eventActivityBO.setDesc(req.getDesc());
        eventActivityBO.setBusinessLine(BusinessSceneEnum.getBusinessSceneEnumByScene(req.getBusinessLine()));
        eventActivityBO.setDecisionId(req.getDecisionId());
        eventActivityBO.setStartTime(req.getStartTime());
        eventActivityBO.setEndTime(req.getEndTime());
        eventActivityBO.setStatus(EventActivityStatusEnum.DRAFT);
        if (CollectionUtils.isNotEmpty(req.getExecuteInfoBOList())) {
            List<EventActivityExecuteInfoBO> executeInfoBOList = new ArrayList<>();
            for (ActivityExecuteInfo activityExecuteInfo : req.getExecuteInfoBOList()) {
                EventActivityExecuteInfoBO executeInfoBO = new EventActivityExecuteInfoBO();
                executeInfoBO.setFlowName(activityExecuteInfo.getFlowName());
                executeInfoBO.setFlowRatio(activityExecuteInfo.getFlowRatio());
                executeInfoBO.setFlowCode(buildFlowCode(activityExecuteInfo));
                executeInfoBO.setIsCompared(activityExecuteInfo.getIsCompared());
                if (activityExecuteInfo.getMessageTouch() != null) {
                    ActivityExecuteInfo.MessageTouch messageTouch = activityExecuteInfo.getMessageTouch();
                    EventActivityExecuteInfoBO.MessageTouch messageTouchBO = new EventActivityExecuteInfoBO.MessageTouch();
                    messageTouchBO.setExecuteClassifyEnum(EventActivityExecuteTouchEnum.getByType(messageTouch.getExecuteClassify()));
                    messageTouchBO.setRelationId(messageTouch.getRelationId());
                    messageTouchBO.setRelationData(messageTouch.getRelationData());
                    messageTouchBO.setIsInterval(messageTouch.getIsInterval());
                    messageTouchBO.setIntervalTime(messageTouch.getIntervalTime());
                    messageTouchBO.setIsDynamicInfo(messageTouch.getIsDynamicInfo());
                    if (CollectionUtils.isNotEmpty(messageTouch.getDynamicWords())) {
                        List<EventActivityDynamicWordEnum> dynamicWordsEnumList = new ArrayList<>();
                        for (String dynamicWord : messageTouch.getDynamicWords()) {
                            dynamicWordsEnumList.add(EventActivityDynamicWordEnum.getByType(dynamicWord));
                        }
                        messageTouchBO.setDynamicWords(dynamicWordsEnumList);
                    }
                    executeInfoBO.setMessageTouch(messageTouchBO);

                }
                if (CollectionUtils.isNotEmpty(activityExecuteInfo.getPropertyRewardList())) {
                    List<EventActivityExecuteInfoBO.PropertyReward> propertyRewardList = new ArrayList<>();
                    for (ActivityExecuteInfo.PropertyReward propertyReward : activityExecuteInfo.getPropertyRewardList()) {
                        EventActivityExecuteInfoBO.PropertyReward propertyRewardBO = new EventActivityExecuteInfoBO.PropertyReward();
                        propertyRewardBO.setRewardEnum(EventActivityExecuteRewardEnum.getByType(propertyReward.getRewardType()));
                        propertyRewardBO.setGrantId(propertyReward.getGrantId());
                        propertyRewardList.add(propertyRewardBO);
                    }
                    executeInfoBO.setPropertyRewardList(propertyRewardList);
                }
                executeInfoBOList.add(executeInfoBO);
            }
            eventActivityBO.setExecuteInfoBOList(executeInfoBOList);
        }

        if (req.getActivityRule() != null) {
            ActivityRule activityRule = req.getActivityRule();
            EventActivityRuleBO eventActivityRuleBO = new EventActivityRuleBO();
            eventActivityRuleBO.setBlackClassify(activityRule.getBlackClassify());
            eventActivityRuleBO.setCrowdClassify(activityRule.getCrowdClassify());
            if (activityRule.getFrequency() != null) {
                ActivityRule.Frequency frequency = activityRule.getFrequency();
                EventActivityRuleBO.Frequency frequencyBO = new EventActivityRuleBO.Frequency();
                frequencyBO.setCount(frequency.getCount());
                frequencyBO.setDay(frequency.getDay());
                eventActivityRuleBO.setFrequency(frequencyBO);
            }
            eventActivityRuleBO.setHitBlackList(activityRule.getHitBlackList());
            eventActivityRuleBO.setHitCrowd(activityRule.getHitCrowd());
            eventActivityBO.setExecuteRule(eventActivityRuleBO);
        }

        eventActivityBO.setCreateUser(req.get_staff().getUsername());
        eventActivityBO.setLastUpdateUser(req.get_staff().getUsername());
        return eventActivityBO;
    }

    public static EventActivityBO convertToEventActivityBO(InsertEventActivityReq req) {
        if (req == null) {
            return null;
        }
        EventActivityBO eventActivityBO = new EventActivityBO();
        eventActivityBO.setId(TodoCommonUtils.buildLongGuid());
        eventActivityBO.setName(req.getName());
        eventActivityBO.setDesc(req.getDesc());
        eventActivityBO.setBusinessLine(BusinessSceneEnum.getBusinessSceneEnumByScene(req.getBusinessLine()));
        eventActivityBO.setDecisionId(req.getDecisionId());
        eventActivityBO.setStartTime(req.getStartTime());
        eventActivityBO.setEndTime(req.getEndTime());
        eventActivityBO.setStatus(EventActivityStatusEnum.DRAFT);
        if (CollectionUtils.isNotEmpty(req.getExecuteInfoBOList())) {
            List<EventActivityExecuteInfoBO> executeInfoBOList = new ArrayList<>();
            for (ActivityExecuteInfo activityExecuteInfo : req.getExecuteInfoBOList()) {
                EventActivityExecuteInfoBO executeInfoBO = new EventActivityExecuteInfoBO();
                executeInfoBO.setFlowName(activityExecuteInfo.getFlowName());
                executeInfoBO.setFlowRatio(activityExecuteInfo.getFlowRatio());
                executeInfoBO.setFlowCode(buildFlowCode(activityExecuteInfo));
                executeInfoBO.setIsCompared(activityExecuteInfo.getIsCompared());
                if (activityExecuteInfo.getMessageTouch() != null) {
                    ActivityExecuteInfo.MessageTouch messageTouch = activityExecuteInfo.getMessageTouch();
                    EventActivityExecuteInfoBO.MessageTouch messageTouchBO = new EventActivityExecuteInfoBO.MessageTouch();
                    messageTouchBO.setExecuteClassifyEnum(EventActivityExecuteTouchEnum.getByType(messageTouch.getExecuteClassify()));
                    messageTouchBO.setRelationId(messageTouch.getRelationId());
                    messageTouchBO.setRelationData(messageTouch.getRelationData());
                    messageTouchBO.setIsInterval(messageTouch.getIsInterval());
                    messageTouchBO.setIntervalTime(messageTouch.getIntervalTime());
                    messageTouchBO.setIsDynamicInfo(messageTouch.getIsDynamicInfo());
                    if (CollectionUtils.isNotEmpty(messageTouch.getDynamicWords())) {
                        List<EventActivityDynamicWordEnum> dynamicWordsEnumList = new ArrayList<>();
                        for (String dynamicWord : messageTouch.getDynamicWords()) {
                            dynamicWordsEnumList.add(EventActivityDynamicWordEnum.getByType(dynamicWord));
                        }
                        messageTouchBO.setDynamicWords(dynamicWordsEnumList);
                    }
                    executeInfoBO.setMessageTouch(messageTouchBO);

                }
                if (CollectionUtils.isNotEmpty(activityExecuteInfo.getPropertyRewardList())) {
                    List<EventActivityExecuteInfoBO.PropertyReward> propertyRewardList = new ArrayList<>();
                    for (ActivityExecuteInfo.PropertyReward propertyReward : activityExecuteInfo.getPropertyRewardList()) {
                        EventActivityExecuteInfoBO.PropertyReward propertyRewardBO = new EventActivityExecuteInfoBO.PropertyReward();
                        propertyRewardBO.setRewardEnum(EventActivityExecuteRewardEnum.getByType(propertyReward.getRewardType()));
                        propertyRewardBO.setGrantId(propertyReward.getGrantId());
                        propertyRewardList.add(propertyRewardBO);
                    }
                    executeInfoBO.setPropertyRewardList(propertyRewardList);
                }
                executeInfoBOList.add(executeInfoBO);
            }
            eventActivityBO.setExecuteInfoBOList(executeInfoBOList);
        }

        if (req.getActivityRule() != null) {
            ActivityRule activityRule = req.getActivityRule();
            EventActivityRuleBO eventActivityRuleBO = new EventActivityRuleBO();
            eventActivityRuleBO.setBlackClassify(activityRule.getBlackClassify());
            eventActivityRuleBO.setCrowdClassify(activityRule.getCrowdClassify());
            if (activityRule.getFrequency() != null) {
                ActivityRule.Frequency frequency = activityRule.getFrequency();
                EventActivityRuleBO.Frequency frequencyBO = new EventActivityRuleBO.Frequency();
                frequencyBO.setCount(frequency.getCount());
                frequencyBO.setDay(frequency.getDay());
                eventActivityRuleBO.setFrequency(frequencyBO);
            }
            eventActivityRuleBO.setHitBlackList(activityRule.getHitBlackList());
            eventActivityRuleBO.setHitCrowd(activityRule.getHitCrowd());
            eventActivityBO.setExecuteRule(eventActivityRuleBO);
        }

        eventActivityBO.setCreateUser(req.get_staff().getUsername());
        eventActivityBO.setLastUpdateUser(req.get_staff().getUsername());
        return eventActivityBO;
    }

    private static String buildFlowCode(ActivityExecuteInfo activityExecuteInfo) {
        return activityExecuteInfo.getFlowName() + activityExecuteInfo.getFlowRatio();
    }

    public static EventActivityBO convertToEventActivityBO(EventActivityPO eventActivityPO) {
        if (eventActivityPO == null) {
            return null;
        }
        EventActivityBO eventActivityBO = new EventActivityBO();
        eventActivityBO.setId(eventActivityPO.getId());
        eventActivityBO.setName(eventActivityPO.getName());
        eventActivityBO.setDesc(eventActivityPO.getDesc());
        eventActivityBO.setBusinessLine(BusinessSceneEnum.getBusinessSceneEnumByScene(eventActivityPO.getBusinessLine()));
        eventActivityBO.setDecisionId(eventActivityPO.getDecisionId());
        eventActivityBO.setStartTime(eventActivityPO.getStartTime());
        eventActivityBO.setEndTime(eventActivityPO.getEndTime());
        eventActivityBO.setStatus(EventActivityStatusEnum.getByType(eventActivityPO.getStatus()));
        eventActivityBO.setExecuteInfoBOList(JSONObject.parseArray(eventActivityPO.getExecuteInfo(), EventActivityExecuteInfoBO.class));
        eventActivityBO.setExecuteRule(JSONObject.parseObject(eventActivityPO.getExecuteRule(), EventActivityRuleBO.class));
        eventActivityBO.setCreateUser(eventActivityPO.getCreateUser());
        eventActivityBO.setLastUpdateUser(eventActivityPO.getLastUpdateUser());
        return eventActivityBO;
    }

    public static EventActivityCondition convertToEventActivityCondition(EventActivityConditionBO eventActivityConditionBO) {
        if (eventActivityConditionBO == null) {
            return null;
        }
        EventActivityCondition eventActivityCondition = new EventActivityCondition();
        eventActivityCondition.setPageIndex(eventActivityConditionBO.getPageIndex());
        eventActivityCondition.setPageSize(eventActivityConditionBO.getPageSize());
        eventActivityCondition.setCurrentIndex(eventActivityConditionBO.getCurrentIndex());
        eventActivityCondition.setBusinessLine(eventActivityConditionBO.getBusinessLine());
        eventActivityCondition.setName(eventActivityConditionBO.getName());
        eventActivityCondition.setDecisionId(eventActivityConditionBO.getDecisionId());
        eventActivityCondition.setStatus(eventActivityConditionBO.getStatus());
        eventActivityCondition.setStartTime(eventActivityConditionBO.getStartTime());
        eventActivityCondition.setEndTime(eventActivityConditionBO.getEndTime());
        return eventActivityCondition;
    }

    public static EventDetailResp convertToEventDetailResp(EventDetailBO eventDetailBO) {
        if (eventDetailBO == null) {
            return null;
        }
        EventDetailResp eventDetailResp = new EventDetailResp();
        eventDetailResp.setId(eventDetailBO.getId());
        eventDetailResp.setEventCode(eventDetailBO.getEventCode());
        eventDetailResp.setBusinessLine(eventDetailBO.getBusinessLine() == null ? null : eventDetailBO.getBusinessLine().getScene());
        eventDetailResp.setEventInfo(convert2EventInfoResp(eventDetailBO.getEventInfo()));
        eventDetailResp.setEventFieldList(convertToEventFieldListResp(eventDetailBO.getEventFieldList()));
        eventDetailResp.setStatus(eventDetailBO.getStatus() == null ? null : eventDetailBO.getStatus().getType());
        eventDetailResp.setCreateUser(eventDetailBO.getCreateUser());
        return eventDetailResp;
    }

    private static List<EventDetailResp.EventField> convertToEventFieldListResp(List<EventDetailBO.EventField> eventFieldList) {
        if (CollectionUtils.isEmpty(eventFieldList)) {
            return Lists.newArrayList();
        }
        List<EventDetailResp.EventField> eventFieldRespList = Lists.newArrayList();
        for (EventDetailBO.EventField eventField : eventFieldList) {
            EventDetailResp.EventField eventFieldResp = new EventDetailResp.EventField();
            eventFieldResp.setDataSource(eventField.getDataSource() == null ? null : eventField.getDataSource().getType());
            eventFieldResp.setTransfer(eventField.getTransfer());
            eventFieldResp.setFieldName(eventField.getFieldName());
            eventFieldResp.setFieldType(eventField.getFieldType() == null ? null : eventField.getFieldType().getType());
            eventFieldResp.setFieldLength(eventField.getFieldLength());
            eventFieldResp.setFieldDesc(eventField.getFieldDesc());
            eventFieldResp.setUniqueField(eventField.getUniqueField());
            eventFieldResp.setOutput(eventField.getOutput());
            eventFieldResp.setSelectOperate(eventField.getSelectOperate() == null ? Lists.newArrayList() : eventField.getSelectOperate().stream().map(SelectOperateEnum::getType).collect(Collectors.toList()));
            eventFieldResp.setSelectType(eventField.getSelectType() == null ? null : eventField.getSelectType().getType());
            if (CollectionUtils.isNotEmpty(eventField.getEnumsValue())) {
                List<EventDetailResp.EnumValue> enumValueRespList = Lists.newArrayList();
                for (EventDetailBO.EnumValue enumValue : eventField.getEnumsValue()) {
                    EventDetailResp.EnumValue enumValueResp = new EventDetailResp.EnumValue();
                    enumValueResp.setKey(enumValue.getKey());
                    enumValueResp.setDesc(enumValue.getDesc());
                    enumValueRespList.add(enumValueResp);
                }
                eventFieldResp.setEnumsValue(enumValueRespList);
            }
            eventFieldRespList.add(eventFieldResp);
        }
        return eventFieldRespList;
    }

    private static EventDetailResp.EventInfo convert2EventInfoResp(EventDetailBO.EventInfo eventInfo) {
        if (eventInfo == null) {
            return null;
        }
        EventDetailResp.EventInfo eventInfoResp = new EventDetailResp.EventInfo();
        eventInfoResp.setEventClassify(eventInfo.getEventClassify() == null ? null : eventInfo.getEventClassify().getType());
        eventInfoResp.setEventType(eventInfo.getEventType() == null ? null : eventInfo.getEventType().getType());
        eventInfoResp.setEventName(eventInfo.getEventName());
        eventInfoResp.setTopicName(eventInfo.getTopicName());
        eventInfoResp.setTag(eventInfo.getTag());
        eventInfoResp.setConsumerName(eventInfo.getConsumerName());
        eventInfoResp.setQueueType(eventInfo.getQueueType() == null ? null : eventInfo.getQueueType().getType());
        eventInfoResp.setRule(eventInfo.getRule());
        return eventInfoResp;
    }

    public static EventInfoConditionBO convertToEventInfoConditionBO(QueryEventDetailPageReq req) {
        if (req == null) {
            return null;
        }
        EventInfoConditionBO eventInfoConditionBO = new EventInfoConditionBO();
        eventInfoConditionBO.setEventCode(req.getEventCode());
        eventInfoConditionBO.setEventName(req.getEventName());
        eventInfoConditionBO.setEventType(req.getEventType());
        eventInfoConditionBO.setEventClassify(req.getEventClassify());
        eventInfoConditionBO.setQueueType(req.getQueueType());
        eventInfoConditionBO.setStatus(req.getStatus());
        eventInfoConditionBO.setCreateUser(req.getCreateUser());
        eventInfoConditionBO.setBusinessLine(req.getBusinessLine());
        eventInfoConditionBO.setPageIndex(req.getPageIndex());
        eventInfoConditionBO.setPageSize(req.getPageSize());
        eventInfoConditionBO.setCurrentIndex(req.getCurrentIndex());
        return eventInfoConditionBO;
    }

    public static PageResult<EventInfoResp> convertToEventInfoRespPage(PageResult<EventInfoBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(new ArrayList<>(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<EventInfoResp> result = new PageResult<>();
        result.setPageCount(pageResult.getPageCount());
        result.setCurrentIndex(pageResult.getCurrentIndex());
        result.setHasNext(pageResult.isHasNext());
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setTotal(pageResult.getTotal());
        result.setResults(pageResult.getResults().stream().map(EventActivityConvert::convertToEventInfoResp).collect(Collectors.toList()));
        return result;
    }

    private static EventInfoResp convertToEventInfoResp(EventInfoBO eventInfoBO) {
        if (eventInfoBO == null) {
            return null;
        }
        EventInfoResp eventInfoResp = new EventInfoResp();
        eventInfoResp.setId(eventInfoBO.getId());
        eventInfoResp.setEventCode(eventInfoBO.getEventCode());
        eventInfoResp.setEventName(eventInfoBO.getEventName());
        eventInfoResp.setEventClassify(eventInfoBO.getEventClassify() == null ? null : eventInfoBO.getEventClassify().getType());
        eventInfoResp.setEventType(eventInfoBO.getEventType() == null ? null : eventInfoBO.getEventType().getType());
        eventInfoResp.setBusinessLine(eventInfoBO.getBusinessLine() == null ? null : eventInfoBO.getBusinessLine().getScene());
        eventInfoResp.setTopicName(eventInfoBO.getTopicName());
        eventInfoResp.setTag(eventInfoBO.getTag());
        eventInfoResp.setConsumerName(eventInfoBO.getConsumerName());
        eventInfoResp.setQueueType(eventInfoBO.getQueueType() == null ? null : eventInfoBO.getQueueType().getType());
        eventInfoResp.setStatus(eventInfoBO.getStatus() == null ? null : eventInfoBO.getStatus().getType());
        eventInfoResp.setCreateUser(eventInfoBO.getCreateUser());
        return eventInfoResp;
    }

    public static EventDecisionDetailResp convertToEventDecisionDetailResp(EventDecisionBO eventDecisionBO) {
        if (eventDecisionBO == null) {
            return null;
        }
        EventDecisionDetailResp eventDecisionDetailResp = new EventDecisionDetailResp();
        eventDecisionDetailResp.setId(eventDecisionBO.getId());
        eventDecisionDetailResp.setName(eventDecisionBO.getName());
        eventDecisionDetailResp.setDesc(eventDecisionBO.getDesc());
        eventDecisionDetailResp.setDecisionType(eventDecisionBO.getDecisionType() == null ? null : eventDecisionBO.getDecisionType().getType());
        eventDecisionDetailResp.setFirstEvent(eventDecisionBO.getFirstEvent());
        if (eventDecisionBO.getFirstEventRule() != null && CollectionUtils.isNotEmpty(eventDecisionBO.getFirstEventRule().getFieldRuleList())) {
            DecisionEventRuleBO firstEventRule = eventDecisionBO.getFirstEventRule();
            List<EventDecisionDetailResp.FieldRule> firstEventRuleRespList = new ArrayList<>();
            for (DecisionEventRuleBO.FieldRule fieldRule : firstEventRule.getFieldRuleList()) {
                EventDecisionDetailResp.FieldRule fieldRuleResp = new EventDecisionDetailResp.FieldRule();
                fieldRuleResp.setFieldName(fieldRule.getFieldName());
                fieldRuleResp.setTypeEnum(fieldRule.getTypeEnum() == null ? null : fieldRule.getTypeEnum().getType());
                fieldRuleResp.setOperateEnum(fieldRule.getOperateEnum() == null ? null : fieldRule.getOperateEnum().getType());
                fieldRuleResp.setOperateValue(fieldRule.getOperateValue());
                firstEventRuleRespList.add(fieldRuleResp);
            }
            eventDecisionDetailResp.setFirstEventRule(firstEventRuleRespList);
        }
        eventDecisionDetailResp.setIntervalTime(eventDecisionBO.getIntervalTime());
        eventDecisionDetailResp.setSecondEvent(eventDecisionBO.getSecondEvent());
        if (eventDecisionBO.getSecondEventRule() != null && CollectionUtils.isNotEmpty(eventDecisionBO.getSecondEventRule().getFieldRuleList())) {
            DecisionEventRuleBO secondEventRule = eventDecisionBO.getSecondEventRule();
            List<EventDecisionDetailResp.FieldRule> secondEventRuleRespList = new ArrayList<>();
            for (DecisionEventRuleBO.FieldRule fieldRule : secondEventRule.getFieldRuleList()) {
                EventDecisionDetailResp.FieldRule fieldRuleResp = new EventDecisionDetailResp.FieldRule();
                fieldRuleResp.setFieldName(fieldRule.getFieldName());
                fieldRuleResp.setTypeEnum(fieldRule.getTypeEnum() == null ? null : fieldRule.getTypeEnum().getType());
                fieldRuleResp.setOperateEnum(fieldRule.getOperateEnum() == null ? null : fieldRule.getOperateEnum().getType());
                fieldRuleResp.setOperateValue(fieldRule.getOperateValue());
                secondEventRuleRespList.add(fieldRuleResp);
            }
            eventDecisionDetailResp.setSecondEventRule(secondEventRuleRespList);
        }
        eventDecisionDetailResp.setUseUnique(eventDecisionBO.getUseUnique());
        eventDecisionDetailResp.setStatus(eventDecisionBO.getStatus() == null ? null : eventDecisionBO.getStatus().getType());
        eventDecisionDetailResp.setCreateUser(eventDecisionBO.getCreateUser());
        eventDecisionDetailResp.setLastUpdateUser(eventDecisionBO.getLastUpdateUser());
        return eventDecisionDetailResp;
    }

    public static EventDecisionConditionBO convertToEventDecisionConditionBO(QueryEventDecisionPageReq req) {
        if (req == null) {
            return null;
        }
        EventDecisionConditionBO eventDecisionConditionBO = new EventDecisionConditionBO();
        eventDecisionConditionBO.setId(req.getId());
        eventDecisionConditionBO.setName(req.getName());
        eventDecisionConditionBO.setDecisionType(req.getDecisionType());
        eventDecisionConditionBO.setStatus(req.getStatus());
        eventDecisionConditionBO.setCreateUser(req.getCreateUser());
        eventDecisionConditionBO.setPageIndex(req.getPageIndex());
        eventDecisionConditionBO.setPageSize(req.getPageSize());
        eventDecisionConditionBO.setCurrentIndex(req.getCurrentIndex());
        return eventDecisionConditionBO;
    }

    public static PageResult<EventDecisionBaseResp> convertToEventDecisionBaseRespPage(PageResult<EventDecisionBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(new ArrayList<>(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<EventDecisionBaseResp> result = new PageResult<>();
        result.setPageCount(pageResult.getPageCount());
        result.setCurrentIndex(pageResult.getCurrentIndex());
        result.setHasNext(pageResult.isHasNext());
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setTotal(pageResult.getTotal());
        result.setResults(pageResult.getResults().stream().map(EventActivityConvert::convertToEventDecisionBaseResp).collect(Collectors.toList()));
        return result;
    }

    private static EventDecisionBaseResp convertToEventDecisionBaseResp(EventDecisionBO eventDecisionBO) {
        if (eventDecisionBO == null) {
            return null;
        }
        EventDecisionBaseResp eventDecisionBaseResp = new EventDecisionBaseResp();
        eventDecisionBaseResp.setId(eventDecisionBO.getId());
        eventDecisionBaseResp.setName(eventDecisionBO.getName());
        eventDecisionBaseResp.setDesc(eventDecisionBO.getDesc());
        eventDecisionBaseResp.setDecisionType(eventDecisionBO.getDecisionType() == null ? null : eventDecisionBO.getDecisionType().getType());
        eventDecisionBaseResp.setFirstEvent(eventDecisionBO.getFirstEvent());
        eventDecisionBaseResp.setIntervalTime(eventDecisionBO.getIntervalTime());
        eventDecisionBaseResp.setSecondEvent(eventDecisionBO.getSecondEvent());
        eventDecisionBaseResp.setUseUnique(eventDecisionBO.getUseUnique());
        eventDecisionBaseResp.setStatus(eventDecisionBO.getStatus() == null ? null : eventDecisionBO.getStatus().getType());
        eventDecisionBaseResp.setCreateUser(eventDecisionBO.getCreateUser());
        eventDecisionBaseResp.setLastUpdateUser(eventDecisionBO.getLastUpdateUser());
        return eventDecisionBaseResp;
    }

    public static EventActivityDetailResp convertToEventActivityDetailResp(EventActivityBO eventActivityBO) {
        if (eventActivityBO == null) {
            return null;
        }
        EventActivityDetailResp eventActivityDetailResp = new EventActivityDetailResp();
        eventActivityDetailResp.setId(eventActivityBO.getId());
        eventActivityDetailResp.setName(eventActivityBO.getName());
        eventActivityDetailResp.setDesc(eventActivityBO.getDesc());
        eventActivityDetailResp.setBusinessLine(eventActivityBO.getBusinessLine() == null ? null : eventActivityBO.getBusinessLine().getScene());
        eventActivityDetailResp.setDecisionId(eventActivityBO.getDecisionId());
        if (eventActivityBO.getExecuteRule() != null) {
            EventActivityRuleBO executeRuleBO = eventActivityBO.getExecuteRule();
            ActivityRule activityRule = new ActivityRule();
            activityRule.setHitBlackList(executeRuleBO.getHitBlackList());
            activityRule.setBlackClassify(executeRuleBO.getBlackClassify());
            activityRule.setHitCrowd(executeRuleBO.getHitCrowd());
            activityRule.setCrowdClassify(executeRuleBO.getCrowdClassify());
            if (executeRuleBO.getFrequency() != null) {
                activityRule.setFrequency(new ActivityRule.Frequency());
                activityRule.getFrequency().setDay(executeRuleBO.getFrequency().getDay());
                activityRule.getFrequency().setCount(executeRuleBO.getFrequency().getCount());
            }
            eventActivityDetailResp.setActivityRule(activityRule);
        }
        if (CollectionUtils.isNotEmpty(eventActivityBO.getExecuteInfoBOList())) {
            List<ActivityExecuteInfo> executeInfoList = new ArrayList<>();
            for (EventActivityExecuteInfoBO executeInfoBO : eventActivityBO.getExecuteInfoBOList()) {
                ActivityExecuteInfo activityExecuteInfo = new ActivityExecuteInfo();
                activityExecuteInfo.setFlowRatio(executeInfoBO.getFlowRatio());
                activityExecuteInfo.setFlowName(executeInfoBO.getFlowName());
                activityExecuteInfo.setFlowCode(executeInfoBO.getFlowCode());
                activityExecuteInfo.setIsCompared(executeInfoBO.getIsCompared());
                if (CollectionUtils.isNotEmpty(executeInfoBO.getPropertyRewardList())) {
                    List<ActivityExecuteInfo.PropertyReward> propertyRewardList = new ArrayList<>();
                    for (EventActivityExecuteInfoBO.PropertyReward propertyRewardBO : executeInfoBO.getPropertyRewardList()) {
                        ActivityExecuteInfo.PropertyReward propertyReward = new ActivityExecuteInfo.PropertyReward();
                        propertyReward.setRewardType(propertyRewardBO.getRewardEnum() == null ? null : propertyRewardBO.getRewardEnum().getType());
                        propertyReward.setGrantId(propertyRewardBO.getGrantId());
                        propertyRewardList.add(propertyReward);
                    }
                    activityExecuteInfo.setPropertyRewardList(propertyRewardList);
                }
                if (executeInfoBO.getMessageTouch() != null) {
                    ActivityExecuteInfo.MessageTouch messageTouch = new ActivityExecuteInfo.MessageTouch();
                    messageTouch.setExecuteClassify(executeInfoBO.getMessageTouch().getExecuteClassifyEnum() == null ? null : executeInfoBO.getMessageTouch().getExecuteClassifyEnum().getType());
                    messageTouch.setRelationId(executeInfoBO.getMessageTouch().getRelationId());
                    messageTouch.setRelationData(executeInfoBO.getMessageTouch().getRelationData());
                    messageTouch.setIsInterval(executeInfoBO.getMessageTouch().getIsInterval());
                    messageTouch.setIntervalTime(executeInfoBO.getMessageTouch().getIntervalTime());
                    messageTouch.setIsDynamicInfo(executeInfoBO.getMessageTouch().getIsDynamicInfo());
                    if (CollectionUtils.isNotEmpty(executeInfoBO.getMessageTouch().getDynamicWords())) {
                        List<String> dynamicWords = new ArrayList<>();
                        for (EventActivityDynamicWordEnum dynamicWord : executeInfoBO.getMessageTouch().getDynamicWords()) {
                            dynamicWords.add(dynamicWord == null ? null : dynamicWord.getCode());
                        }
                        messageTouch.setDynamicWords(dynamicWords);
                    }
                    activityExecuteInfo.setMessageTouch(messageTouch);
                }
                executeInfoList.add(activityExecuteInfo);
            }
            eventActivityDetailResp.setExecuteInfoBOList(executeInfoList);
        }
        eventActivityDetailResp.setStatus(eventActivityBO.getStatus() == null ? null : eventActivityBO.getStatus().getType());
        eventActivityDetailResp.setStartTime(eventActivityBO.getStartTime());
        eventActivityDetailResp.setEndTime(eventActivityBO.getEndTime());
        return eventActivityDetailResp;
    }

    public static EventActivityConditionBO convertToEventActivityConditionBO(QueryEventActivityPageReq req) {
        if (req == null) {
            return null;
        }
        EventActivityConditionBO conditionBO = new EventActivityConditionBO();
        conditionBO.setPageIndex(req.getPageIndex());
        conditionBO.setPageSize(req.getPageSize());
        conditionBO.setName(req.getName());
        conditionBO.setBusinessLine(req.getBusinessLine());
        conditionBO.setStatus(req.getStatus());
        conditionBO.setDecisionId(req.getDecisionId());
        conditionBO.setStartTime(req.getStartTime());
        conditionBO.setEndTime(req.getEndTime());
        conditionBO.setCurrentIndex(req.getCurrentIndex());
        return conditionBO;
    }

    public static PageResult<EventActivityInfoResp> convertToEventActivityInfoRespPage(PageResult<EventActivityBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(new ArrayList<>(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<EventActivityInfoResp> result = new PageResult<>();
        result.setPageCount(pageResult.getPageCount());
        result.setCurrentIndex(pageResult.getCurrentIndex());
        result.setHasNext(pageResult.isHasNext());
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setTotal(pageResult.getTotal());
        result.setResults(pageResult.getResults().stream().map(EventActivityConvert::convertToEventActivityInfoResp).collect(Collectors.toList()));
        return result;
    }

    private static EventActivityInfoResp convertToEventActivityInfoResp(EventActivityBO eventActivityBO) {
        if (eventActivityBO == null) {
            return null;
        }
        EventActivityInfoResp eventActivityInfoResp = new EventActivityInfoResp();
        eventActivityInfoResp.setId(eventActivityBO.getId());
        eventActivityInfoResp.setName(eventActivityBO.getName());
        eventActivityInfoResp.setDesc(eventActivityBO.getDesc());
        eventActivityInfoResp.setBusinessLine(eventActivityBO.getBusinessLine() == null ? null : eventActivityBO.getBusinessLine().getScene());
        eventActivityInfoResp.setDecisionId(eventActivityBO.getDecisionId());
        eventActivityInfoResp.setStatus(eventActivityBO.getStatus() == null ? null : eventActivityBO.getStatus().getType());
        eventActivityInfoResp.setStartTime(eventActivityBO.getStartTime());
        eventActivityInfoResp.setEndTime(eventActivityBO.getEndTime());
        return eventActivityInfoResp;
    }
}
